// Dom7
var $$ = Dom7;

// Framework7 App main instance
var app = new Framework7({
	root: '#app', // App root element
	id: 'io.yachtar.app', // App bundle ID
	name: 'Yachtar', // App name
	theme: 'auto', // Automatic theme detection
	dialog: {
		// set default title for all dialog shortcuts
		title: '提示',
		// change default "OK" button text
		buttonOk: '确认',
	},
});

// Init/Create main view
var mainView = app.views.create('.view', {
	url: '/'
});

var buildingid;
var cellid;
var houseid;
var housedata;
$(document).ready(function () {
	//830 house 820 build 821 cell
	var serialno = sessionStorage.getItem("serialno");
	var givetype = sessionStorage.getItem("givetype");
	call_remote(REQUEST_TYPE820, {serialno:serialno,givetype:givetype},function(data){
		$("#buildingid").combobox('loadData',data);
	});
	$("#buildingid").combobox({
		onChange:function(newValue){
			buildingid = newValue;
			call_remote(REQUEST_TYPE821, {serialno:serialno,givetype:givetype,buildingid:buildingid},function(data){
				$("#cellid").combobox('loadData',data);
			});
		}
	});
	$("#cellid").combobox({
		onChange:function(newValue){
			cellid = newValue;
			call_remote(REQUEST_TYPE830, {serialno:serialno,givetype:givetype,buildingid:buildingid,cellid:cellid},function(data){
				$("#houseid").combobox('loadData',data);
			});
		}
	});
	$("#houseid").combobox({
		onChange:function(newValue){
			houseid = newValue;
			call_remote(REQUEST_TYPE830, {serialno:serialno,givetype:givetype,buildingid:buildingid,cellid:cellid,houseid:houseid},function(data){
				housedata = data[0];
				$("#location").html(data[0].location);
				$("#area").html(data[0].area);
				$("#devertrate").html(data[0].devertrate);
				$("#devert").html(data[0].devert);
			});
		}
	});
});


//返回
$$('#backimg').on('click', function () {
	window.location.href = "../../plugin/vote/votedetail.html";
});

$$('#savecon').on('click', function () {
	var dataArray = [];
	housedata.cardid = $('#cardid').val();
	dataArray.push(housedata);
	call_remote(REQUEST_TYPE834, {data:dataArray},function(data){
		app.dialog.alert("保存成功！");
	});
});

$$('#gowaitcard').on('click', function () {
	window.location.href = "../../plugin/vote/waitcard.html";
});